﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using CloudClipboardSync.Utils;

namespace CloudClipboardSync.Converters
{
    public class VisibleIfConverter : IValueConverter
    {
        public VisibleIfConverter()
        {
            Hide = false;
        }

        public bool IfNotMatch { get; set; }
        public bool Hide { get; set; }
        public Visibility NonVisValue { get { return Hide ? Visibility.Hidden : Visibility.Collapsed; } }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (GuiTools.IsDesignTime) return Visibility.Visible;

            var match = Equals(value, parameter) || Equals((value ?? "null").ToString(), parameter);
            if(IfNotMatch) 
                match = !match;
            return match ? Visibility.Visible : NonVisValue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
    }
}
